# from dsProject1.logger.create_logger import log_creater
import logging
import time
import os
import colorlog
from configuration.log_config import LogConfig


class Log:
    def __init__(self, output_dir: str):
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)
        log_name = '{}.log'.format(time.strftime('%Y-%m-%d-%H-%M'))
        final_log_file = os.path.join(output_dir, log_name)
        # creat a logger
        logger = logging.getLogger(LogConfig.LOGGER_NAME)
        logger.setLevel(logging.DEBUG)
        # FileHandler
        file = logging.FileHandler(final_log_file)
        file.setLevel(LogConfig.FILE_LOG_LEVEL)
        # StreamHandler
        stream = colorlog.StreamHandler()
        stream.setLevel(LogConfig.STEAM_LOG_LEVEL)
        # Formatter
        stream_formatter = colorlog.ColoredFormatter(
            LogConfig.STREAM_FORMATTER,
        )
        file_formatter = colorlog.ColoredFormatter(
            LogConfig.FILE_FORMATTER,
        )
        # setFormatter
        file.setFormatter(file_formatter)
        stream.setFormatter(stream_formatter)
        # addHandler
        logger.addHandler(file)
        logger.addHandler(stream)
        logger.info('creating {}'.format(final_log_file))
        self.logger = logger
log = Log("111").logger















